<?php
declare (strict_types = 1);

namespace app\api\controller\yuql;

use app\logic\yuql\LoginLogic;
use app\services\yuql\AuthenticationServices;
use app\validate\yuql\LoginValidate;
use think\Request;

class Wxlogin
{
    /**
     * yuql
     * 登录控制器
     * @param Request $request
     * @return \think\response\Json
     */
    public function login(Request $request){
        if (!$request->isPost()) return writeJson(1002,'',"请求方式不对");
        try {
            $params = $request->post();
            $res = LoginLogic::wxlogins($params);
            if ($res){
                return writeJson(1001,$res,'登陆成功');
            }
        } catch (\Exception $e){
            return writeJson(1002,'',$e->getMessage());
        }
    }

    /**
     * yuql
     * 发送验证码
     * @param Request $request
     * @return \think\response\Json
     */
    public function smsSend(Request $request){
        try {
            $phone = $request->post('phone');
            $res = LoginLogic::loginSend($phone);
            if ($res){
                return writeJson(1001,$res,'短信发送成功');
            }
        } catch (\Exception $e){
            return writeJson(1002,'',$e->getMessage());
        }
    }

    /**
     * yuql
     * 验证码校验登录注册
     * @param Request $request
     * @return \think\response\Json
     */
    public function register(Request $request){
        try {
            $params = $request->post();
            $res = LoginLogic::register($params);
            if ($res) return writeJson(1001,$res,'注册成功');
        }catch (\Exception $e){
            return writeJson(1002,'',$e->getMessage());
        }
    }

    /**
     * yuql
     * 注册成功设置密码
     * @param Request $request
     * @return \think\response\Json
     */
    public function userSetPwd(Request $request){
        try {
            $params = $request->post();
            $res = LoginLogic::setPassword($params);
            if ($res) return writeJson(1001,$res,'密码设置成功');
        }catch (\Exception $e){
            return writeJson(1002,'',$e->getMessage());
        }
    }
}
